<?php 
class new_list extends Controller {

	var $event 				= '';
	var	$obj_new_list		= '';
	var $m_nid				= '';
	var $m_language			= 'eng';
	/* Paging*/
	var $ctr_name			= '';
	var	$ncurrent_page		= 1;
	var	$nrow_per_page		= 8;
	var $ntotal_row			= 0;
	var $total_page			= 0;
	
	var $nrow_sec_view		= 5;
	/* Paging*/
	var $nid_section		= '';
	var $nid_cat			= '';
	
	var	$title					= '';
	var	$tags					= '';
	var	$description			= ''; 

function new_list()
	{
		parent::Controller();	
		session_start();
		
		$this->load->database();	
		$this->load->helper('ap_function');
		$this->load->helper('ap_object');
		$this->load->helper('ap_html');
		$this->load->helper('ap_view_helper');
		$this->load->helper('ap_db');
		$this->load->helper('ap_module');
		$this->load->model('news_section_model');
		$this->load->language('ap', 'eng');
	}

// Dinh nghia ham rut gon khi set language cho cac label.
// 
private function m_language_key($str_key)
{
	return $this->lang->line('lbl.new_list.'.$str_key);
}

function page ($page = '', $nid_sec = '',$nid_cat = '')
{
	if($nid_sec == 14)
	{
		$this->nrow_per_page	= $this->nrow_sec_view;
		$this->event			= 'view_sec';
		
	}
	
	$this->nid_section		= $nid_sec;
	$this->nid_cat			= $nid_cat;
	$this->ncurrent_page	= $page;
	$this->do_process();
}

function cat($nid_sec,$nid_cat)
{
	$this->nid_section	= $nid_sec;
	$this->nid_cat	= $nid_cat;
	$this->event	= 'view_cat';
	$this->do_process();
}

function sec($nid_sec)
{
	$this->nid_section		= $nid_sec;
	$this->event			= 'view_sec';
	$this->nrow_per_page	= $this->nrow_sec_view;
	$this->do_process();
}

function index()
{
	$this->do_process();
}

function detail($nid)	
{
	$this->m_nid 	= $nid;
	$this->event	='detail';
	$this->do_process() ;
}	
function do_process() 
{
	$this->get_data(); 		
	$this->caculate_data(); 		
	$this->do_business(); 		
	$this->destroy_data();
}
	
private function get_data()
{  
	
}
	
private function caculate_data()
{
	$this->load->language('ap', $this->m_language);
	$str_where_new_list			= $this->get_where_new_list_string();
	$this->ntotal_row			= $this->news_section_model->count_record($str_where_new_list);
	$this->total_page			= Fget_total_page($this->nrow_per_page, $this->ntotal_row);
	
	$this->ctr_name				= 'new_list';
	$this->obj_new_list			= $this->news_section_model->get_listview($str_where_new_list,'ddate01','asc',$this->nrow_per_page,$this->ncurrent_page,$this->ntotal_row);
 	$this->event				= $this->event == ''?'view':$this->event;
}

private function do_business()
{	
	$data['lbl_tinmoi']			= $this->m_language_key('tinmoi');
	$data['lbl_tin']			= $this->m_language_key('tin');
	$data['link_page']			= base_url().'new_list';
	//$data['paging']				= Fpaging_news($this->ntotal_row,$this->ncurrent_page,$this->nrow_per_page,$this->ctr_name,$this->nid_section,$this->nid_cat);
	if($this->nid_cat == 4)
	{
		$param					= 'gamers-profile/page';
		$data['paging']			= Fgen_pagination2($this->ncurrent_page, $this->total_page, base_url(), $param);
	}
	else if($this->nid_cat == 5)
	{
		$param					= 'teams-profile/page';
		$data['paging']			= Fgen_pagination2($this->ncurrent_page, $this->total_page, base_url(), $param);
	}
	else
	{
		$param					= '/'.$this->nid_section.'/'.$this->nid_cat;
		$data['paging']			= Fgen_pagination($this->ncurrent_page, $this->total_page, base_url().'new_list/page/', $param);
	}
	
	$data['event']				= $this->event;
	$data['nid_cat']			= $this->nid_cat;
	$data['nid_sec']			= $this->nid_section;
	$data['ntotal_row']			= $this->ntotal_row;
	
	if($this->nid_section != '')
	{
		$obj_data					= get_section_news_byid($this->nid_section);
		$this->title				= $obj_data['csection_news'];
		$this->tags					= $obj_data['ctag'];
		$this->description			= $obj_data['cnote'];
	}
		
	if($this->nid_cat != '')
	{
		$obj_cat					= get_mod_cat_news_byid($this->nid_cat);
		$this->title				= $obj_cat['ccat_news'];
		$this->tags					= $obj_cat['ctag'];
		$this->description			= $obj_cat['cnote'];
	}
	
	$data['obj_new_list']		= $this->obj_new_list;
	
	$data['menu_sec']			= '';
	$data['menu_cat']			= '';
	
	$data['title']			= $this->title;
	$data['tags']			= $this->tags;
	$data['description']	= $this->description;
	$data['g_ishome']		= 0;	
	if($this->event	== 'view_cat')
		$this->load->view('new_list/index',$data);
	else if($this->event	== 'view_sec')
		$this->load->view('new_list/list',$data);
	else
		$this->load->view('new_list/index',$data);
		
		
}
	
private function destroy_data()
{
			
}
private function get_where_new_list_string()
{
//		$str		= 'where nstatus = "1"';	
		$str = ' WHERE nid is not null ';
		if($this->nid_section != '')
		$str .= ' AND nid_section_news = '.$this->nid_section;
		if($this->nid_cat != '')
		$str .= ' AND nid_cat = '.$this->nid_cat;
		return $str ;
}

}